
<template>
	<div>
        <Row>
            <div>
                <Button :type="active===1?'primary':'default'" plain  @click="active=1">血糖</Button>
                <Button :type="active===2?'primary':'default'" plain  @click="active=2">血压</Button>
                <Button :type="active===3?'primary':'default'" plain  @click="active=3">血脂</Button>
                <Button :type="active===4?'primary':'default'" plain  @click="active=4">尿酸</Button>
                <Button :type="active===5?'primary':'default'" plain  @click="active=5">慢肺病</Button>
            </div>
            <div class="tip">
                <Alert>监测总数：{{count}}次；偏低总数：{{higherCount}}次；偏高总数：{{lowerCount}}次；最低值：<span style="color:#FF9900;">{{minValue}}</span>mmol/L；最高值：<span style="color:#ED4014;">{{maxValue}}</span>mmol/L；</Alert>
                <Table :loading="loading" :columns="tableColumns" :data="items">
                    <template slot-scope="{ row }" slot="testDate">
                        <span>{{row.testDate | YMDHMS}}</span>
                    </template>

                </Table>
            </div>
        </Row>
    </div>
</template>
<script>
import { statStat } from '@api/stat.js'
import { testGetStatSugar, testPageQueryGroupSugar, testGetSugarDic } from '@api/test.js'
import { mapState } from '@lib/x_.js';

export default {
    props: {
        cur: {
            type: Object,
            required: true,
            default: {},
        }
    },
    data() {
        return {
            active: 1,
            count: 0,
            higherCount: 0,
            lowerCount: 0,
            minValue: 0,
            minValue: 0,
            maxValue: 0,
            items:[],
            tableColumns: [
                {
                    title: '日期',
                    align: 'left',
                    width: 170,
                    slot:'testDate',
                },
            ]
        }
    },
    computed: {
        ...mapState(['sugarTime'])
    },
    mounted() {
        const { id } = this.cur;
        if (id) {
            this.testGetStatSugar(id)
            this.testPageQueryGroupSugar(id)
        }
        this.initC()
    },
    methods: {
        getSugarTime(row){
            const { timeType } = row;

        },
        testPageQueryGroupSugar(id) {
            testPageQueryGroupSugar(
                {
                    customerId: id,
                    page:1,
                    pageSize:5
                }
            ).then(res => {
                console.log("testPageQueryGroupSugar>", res)
                if (res.code === "0") {
                    this.items = res.data.items;
                }
            })
        },
        testGetStatSugar(id) {
            testGetStatSugar({customerId: id}).then((res => {
                const { count,higherCount,lowerCount,minValue,maxValue } = res;
                this.count       = res.data.count || 0;
                this.higherCount = res.data.higherCount || 0;
                this.lowerCount  = res.data.lowerCount || 0;
                this.minValue    = res.data.minValue || 0;
                this.maxValue    = res.data.maxValue || 0;
                
                // autoFlag: null
                // birthday: null
                // count: 0
                // createTime: null
                // customerFileNumber: null
                // customerId: null
                // customerName: null
                // higherCount: 0
                // id: null
                // lowerCount: 0
                // maxValue: null
                // minValue: null
                // mobile: null
                // normalCount: 0
                // organId: null
                // projectCode: null
                // remark: null
                // sex: null
                // snCode: null
                // synckey: null
                // testDate: null
                // testResult: null
                // testTime: null
                // testValue: null
                // timeType: null
                // updateTime: null

            }))
        },
        statStat(){
            statStat({
                bizCodes: ['customer_intervention','customer_follow'],
            }).then(res => {
                console.log("data statStat-->", res)
            })
        },
        initC() {
            const arr = []
            this.sugarTime.map((item,i) => {
                arr.push({
                    width: 100,
                    title: item.name,
                    align: 'left',
                    key: item.timeType,
                },)
            })
            this.tableColumns = [...this.tableColumns,...arr]
            console.log('tableColumns-->' ,this.tableColumns)
        }
    },
    watch: {
        cur(after){
            const { id } = after;
            this.testGetStatSugar(id)
            this.testPageQueryGroupSugar(id)
        },
        testGetSugarDic(after){
            this.initC()
        }
    }
}
</script>
<style scoped>
    .tip{
        padding-top: 10px;
    }
</style>
